import Vue from 'vue'
import Vuex from 'vuex'
import { getItem, setItem } from '@/utils/storage'
Vue.use(Vuex)

const tokenKet = 'TOUTIAO_USER'

export default new Vuex.Store({
  state: {
    // 用来存储用户的token
    // user: JSON.parse(window.localStorage.getItem(tokenKet))
    user: getItem(tokenKet)
  },
  mutations: {
    setUser (state, data) {
      state.user = data
      // 为了防止刷新丢失 需要备份到本地存储
      // window.localStorage.setItem(tokenKet, JSON.stringify(state.user))
      setItem(tokenKet, state.user)
    }
  },
  actions: {
  },
  modules: {
  }
})
